package com.app.utils.impl.labour;

import com.app.utils.impl.IConsole;
import com.app.utils.impl.Strategy;
import com.app.utils.temp.Person;
import com.zndroid.utils.XUtils;
import com.zndroid.utils.impl.CollectUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by lzy on 2022/2/15.
 */
public class CollectUtilStrategy extends Strategy {

    public CollectUtilStrategy(IConsole iConsole) {
        super(iConsole);
    }

    @Override
    public void doing() {
        CollectUtil util = XUtils.create().collectUtil();

        ////基本类型
        String[] A = new String[]{"hello", "da", "mei", "nv", "jia", "ge", "wechat"};
        String[] B = new String[]{"hello", "da", "mei", "nan", "not", "jia"};

        List<String> list = util.AuB(Arrays.asList(A), Arrays.asList(B));
        List<String> list2 = util.AnB(Arrays.asList(A), Arrays.asList(B));
        List<String> list11 = util.ADupB(Arrays.asList(A), Arrays.asList(B));

        StringBuilder stringBuilder = new StringBuilder();

        for (String s : list) {
            stringBuilder.append(s).append("\n");
        }

        iConsole.console("\nA= {\"hello\", \"da\", \"mei\", \"nv\", \"jia\", \"ge\", \"wechat\"} \nB= {\"hello\", \"da\", \"mei\", \"nan\", \"not\", \"jia\"}", "");
        iConsole.console("AuB", stringBuilder.toString());

        StringBuilder stringBuilder1 = new StringBuilder();
        for (String s : list2) {
            stringBuilder1.append(s).append("\n");
        }

        iConsole.console("\nA= {\"hello\", \"da\", \"mei\", \"nv\", \"jia\", \"ge\", \"wechat\"} \nB= {\"hello\", \"da\", \"mei\", \"nan\", \"not\", \"jia\"}", "");
        iConsole.console("AnB", stringBuilder1.toString());

        StringBuilder stringBuilder11 = new StringBuilder();
        for (String s : list11) {
            stringBuilder11.append(s).append("\n");
        }
        iConsole.console("\nA= {\"hello\", \"da\", \"mei\", \"nv\", \"jia\", \"ge\", \"wechat\"} \nB= {\"hello\", \"da\", \"mei\", \"nan\", \"not\", \"jia\"}", "");
        iConsole.console("ADupB", stringBuilder11.toString());

        ////自定义对象
        List<Person> AA = new CopyOnWriteArrayList<>();
        List<Person> BB = new CopyOnWriteArrayList<>();
        {
            Person p1 = new Person();
            p1.setName("张三");
            p1.setAge(18);
            p1.setSex(true);
            p1.setIdCard(111111111);

            Person p2 = new Person();
            p2.setName("李四");
            p2.setAge(19);
            p2.setSex(true);
            p2.setIdCard(222222222);

            Person p3 = new Person();
            p3.setName("王五");
            p3.setAge(20);
            p3.setSex(false);
            p3.setIdCard(333333333);

            AA.add(p1);
            AA.add(p2);
            AA.add(p3);

            Person p4 = new Person();
            p4.setName("张三");
            p4.setAge(18);
            p4.setSex(true);
            p4.setIdCard(111112222);

            Person p5 = new Person();
            p5.setName("李四");
            p5.setAge(19);
            p5.setSex(true);
            p5.setIdCard(222222222);

            BB.add(p4);
            BB.add(p5);
        }
        List<Person> list3 = XUtils.create().collectUtil().AuB(AA, BB);
        List<Person> list4 = XUtils.create().collectUtil().AnB(AA, BB);
        List<Person> list5 = XUtils.create().collectUtil().A_AnB(AA, BB);

        iConsole.console("自定义对象集合", "");

        StringBuilder stringBuilder2 = new StringBuilder();
        for (Person s : list3) {
            stringBuilder2.append(s).append("\n");
        }

        iConsole.console("A= {张三1，李四， 王五} \nB= {张三2，李四}", "");
        iConsole.console("AuB", stringBuilder2.toString());

        StringBuilder stringBuilder3 = new StringBuilder();
        for (Person s : list4) {
            stringBuilder3.append(s).append("\n");
        }

        iConsole.console("A= {张三1，李四， 王五} \nB= {张三2，李四}", "");
        iConsole.console("AnB", stringBuilder3.toString());

        StringBuilder stringBuilder4 = new StringBuilder();
        for (Person s : list5) {
            stringBuilder4.append(s).append("\n");
        }

        iConsole.console("A= {张三1，李四， 王五} \nB= {张三2，李四}", "");
        iConsole.console("A_AnB", stringBuilder4.toString());

        iConsole.console("CollectionIsEmpty?[new ArrayList<String>()]", util.isEmpty(new ArrayList<String>()) + "");
    }
}
